from os import path
from datetime import datetime
from queue import Queue

from pandas import DataFrame

from .singleton import singleton
from project.project_info import project_dic

# 当前文件所在目录的父目录的绝对路径
ProjDirPath = path.dirname(path.dirname(path.abspath(__file__)))

FilesPath = path.join(ProjDirPath, "a_file")
Contract_Excel_path = path.join(FilesPath, "file", "contract.xlsx")
DBPath = path.join(FilesPath, "db", "work.db")
PROJECT_PATH = path.join(ProjDirPath, "project.json")
IE_32_driver_path = path.join(FilesPath, "file", "IEDriverServer.exe")
LOGO_PNG = path.join(FilesPath, "img", "nuclear.png")
LOGO_ICO = path.join(FilesPath, "img", "logo.ico")
NAS_PATH = r"\\cnpec-nas01\PSE\PND核岛主设备采购分部\合同文本管理"
LOCAL_Contract_PATH = "E:\\work"
Web_Operator = path.join(FilesPath, "file", "web_operator.xlsx")
Token_str = None
Playwright_DDL_Path = path.join(FilesPath, "file", "playwright_ddl.xlsx")
WebDriver_DDL_Path = path.join(FilesPath, "file", "web_driver.xlsx")
File_Temp = r"E:\\work\file_temp"
DRCS_Overall_View = "详见详细意见"
Sender_Str = "中广核工程有限公司 设备采购与成套中心 核岛主设备分部 张斌 经理"


def get_path(file_list):
    path_str = ProjDirPath
    for file in file_list:
        path_str = path.join(path_str, file)
    return path_str


@singleton
class Public_Data:
    def __init__(self):
        self.Run_time = datetime.now()  # 程序的开始运行时间
        self.Df_Contract: DataFrame = DataFrame()  # 合同信息
        self.Show_File_Count = 500  # 展示的文函数量
        self.Project_list = []  # 项目列表
        self.Factory_list = []  # 制造厂列表
        self.Lot_list = []  # 采购包列表
        self.Df_Show_Contract = None  # 合同展示列表
        self.Token = None  # 身份验证信息
        self.Token_time = None  # 获取Token的时间
        self.File_update_Time = ""  # 文函的更新日期
        self.file_json_queue: Queue = Queue(100)
        self.file_dic_list_queue: Queue = Queue(1000)
        self.update_all = True
        self.contract_info_dict = {}


public_data = Public_Data()


def get_project_name(prj_code):
    """获取DRCS中的项目名"""
    return project_dic[prj_code]
